import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const state = {
  cartCount: 0, // 购物车数量
}

// 同步加载
const mutations = {
  setCartCount(state, count) {
    state.cartCount = count
  },
}

// 异步加载
const actions = {
  setCartCount({ commit }, count) {
    commit('SET_CARTCOUNT', count)
  },
}

// 计算属性
const getters = {
  cartCount: (state) => state.cartCount,
}

export default new Vuex.Store({
  state,
  mutations,
  getters,
  actions,
})
